  export function changeUseName(data){
    return {
      type:"CAHNGNAME",
      data
    }
  }
  export function loginState(){
    return {
      type:"FALSELOGIN"
    }
  }
  
  export function userLogin(user={name:0,password:0}){
    return dispatch=>{
      
      return fetch('http://10.31.160.25:3000/users/list',{
        method: "POST",
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body:"name="+user.name+"&password="+ user.password
      })
      .then(res=>{ 
      
        return res.json()
      })
      .then(data=>{
        if(data.rows.length==0){
            alert('用户名不存在')
          }
        if(data.rows[0].name&&data.rows[0].password==user.password){
          
          
          dispatch(changeUseName(data.rows[0]))       
        }else{
          alert("密码错误")
          dispatch(loginState())   
        }
    
      })
    }  
  }